package com.huangbc.servicemap.controller;

import com.huangbc.internalcommon.dto.ResponseResult;
import com.huangbc.internalcommon.dto.ServiceRequest;
import com.huangbc.servicemap.service.ServiceFromMapService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: Derek.huang on 2024/3/29 19:24.
 */
@RestController
@RequestMapping("/service")
@Slf4j
public class ServiceController {

    @Autowired
    private ServiceFromMapService serviceFromMapService;

    /**
     * 创建服务
     * @param name
     * @return
     */
    @PostMapping("/add")
    public ResponseResult add(String name){

        return serviceFromMapService.add(name);
    }

    /**
     * 查询服务
     * @param amapKey 服务key
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestParam(value = "amapKey") String amapKey){
        log.info("查询服务的key:{}",amapKey);
        return serviceFromMapService.list(amapKey);
    }

    /**
     * 删除服务
     * @param serviceRequest 删除服务的key & 服务id
     * @return
     */
    @PostMapping("/delete")
    public ResponseResult delete(@RequestBody ServiceRequest serviceRequest){
        log.info("删除服务:{}",serviceRequest);
        return serviceFromMapService.delete(serviceRequest);
    }
}

